﻿
@{
    ViewBag.Title = "价格审核";
    var order = ViewBag.Order as CubicFWNet.Data.ViewModal.OrderInfo;
    var opList = ViewBag.OpList as IEnumerable<CubicFWNet.Data.ViewModal.ProductView>;
}


<section class="content-header">
    <h1>
        价格审核
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index","Home")">首页</a></li>
        <li class="active">价格审核</li>
    </ol>
</section>

<section class="content">
    <form class="form-horizontal" method="post" id="formMain">
        <div class="box box-solid">
            <div class="box-body">
                <div class="row">
                    <input type="hidden" name="OrderID" id="OrderID" value="@order.Id" />

                    <div class="form-group col-md-6 col-sm-12" style="display:none">
                        <label for="Number" class="col-sm-3 control-label">订单编号</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Number" name="Number" value="@order.Number" readonly />
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12">
                        <label for="CusName" class="col-sm-3 control-label">客户名称</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="CusName" name="CusName" value="@order.CustomerName" readonly />
                        </div>
                    </div>

                    <div class="form-group col-md-6 col-sm-12" style="display:none">
                        <label for="InitPrice" class="col-sm-3 control-label">订单总价</label>
                        <div class="col-sm-9">
                            <input type="number" class="form-control" id="InitPrice" name="InitPrice" value="@order.InitPrice" readonly />
                        </div>
                    </div>
                </div>
            </div>
            <input type="hidden" id="Data" name="Data" />
            <div id="divProList ">
                @foreach (var item in opList)
                {
                    <div class="row panelLayout" id="@item.Id">
                        <div class="form-group col-md-6 col-sm-12">
                            <label class="col-sm-3 control-label">产品名称</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" value="@item.Name" readonly />
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label class="col-sm-3 control-label">产品数量</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control ProAmount" value="@item.Amount" readonly />
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label class="col-sm-3 control-label">成本价</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control ProCost" value="@item.CostPrice" readonly />
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label class="col-sm-3 control-label">利润比</label>
                            <div class="col-sm-9">
                                @if (item.CostPrice > 0)
                                {
                                    decimal ratio = (@item.Price - @item.CostPrice) / @item.CostPrice;
                                    <input type="text" class="form-control ProCost" value="@ratio" readonly />
                                }
                                else
                                {
                                    <input type="text" class="form-control ProCost" value="0" readonly />
                                }
                              
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label class="col-sm-3 control-label">指导价</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control ProCost" value="@item.Price" readonly />
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label class="col-sm-3 control-label">最终价</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control ProFinal" id="@item.Id" value="@item.FinalPrice" />
                            </div>
                        </div>

                    </div>
                }
            </div>

            <div class="row">

            </div>
        </div>
        <div class="box-footer">
            <div class="box-footer">
                <span class="btn btn-primary " onclick="FormSub()">审核通过</span>&nbsp;&nbsp;&nbsp;&nbsp;
                <a class="btn btn-primary" href="@Url.Action("ApplyList","SalerDirector")">返 回</a>&nbsp;&nbsp;&nbsp;&nbsp;
                <label class="danger">@ViewBag.Info</label>
                <div class="text-red" style="margin-top:20px;font-weight:bold">下一步：产品管理-->确认下单</div>
            </div>
        </div>
    </form>
</section>
<script src="~/Scripts/jQuery/jquery-2.2.3.min.js"></script>
<script>

    //提交数据
    function FormSub() {
        //验证最终价
        var num = $(".ProFinal").size();
        for (i = 0; i < num; i++) {
            var price = $(".ProFinal").eq(i).val();
            if (price == null || price == "" || price <= 0) {
                $.modalAlert("请输入正确的价格！", "warning");
                return false;
            }
        }
        var data = getParam();
        $("#Data").val(data);

        $("#formMain").submit();
    }

    //获取Json数据
    function getParam() {
        var postdata = [];
        var num = $(".ProFinal").size();
        for (i = 0; i < num; i++) {
            var $this = $(".ProFinal").eq(i);
            var id = $this.attr('id');
            var value = $this.val();
            postdata.push({ ID: id, Price: value });
        }
        return JSON.stringify(postdata);
    }

</script>